package org.dandsoft.blackbox.snn.util.automaton;

import com.sun.org.apache.xerces.internal.impl.xpath.XPath;

/**
 * Created by IntelliJ IDEA.
 * User: dvilyuzhanin
 * Date: 08.04.2009 11:19:52
 */
public abstract class AbstractLoopConnection<StateType extends State> implements Connection {
    private int repeatsCount;

    public AbstractLoopConnection() {
    }

    public AbstractLoopConnection(int repeatsCount) {
        this.repeatsCount = repeatsCount;
    }

    protected abstract int getCounter(StateType state);

    protected abstract void incrementCounter(StateType state);

    public boolean isGoOut(State state) {
        int counter = getCounter((StateType) state);
        if (counter < repeatsCount) {
            incrementCounter((StateType) state);
            return true;
        } else {
            return false;
        }
    }

    public int getRepeatsCount() {
        return repeatsCount;
    }

    public void setRepeatsCount(int repeatsCount) {
        this.repeatsCount = repeatsCount;
    }
}
